home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 08 - 1992 / 08.03 Jul 92 / Fast Random Numbers / Test.p < prev    next >
Encoding:
Text File  |  1991-10-04  |  1.6 KB  |  58 lines  |  [TEXT/MPS ]

  1. program TestRandomNumbers (input, output);
  2.  
  3. {  This program tests the random number generator implemented
  4.    by the unit RandomNumbers.  If the generator is the "minimal
  5.    standard generator" (multiplicative linear congruential
  6.    algorithm with modulus 2147483647 and multiplier 16807, and
  7.    the initial seed is 1, the value of the seed after 10000
  8.    iterations should be 1043618065.  If this value is not
  9.    obtained, then the generator either is not a "minimal
  10.    standard" generator, or has failed due to integer overflow
  11.    at some point.
  12.  
  13.    Under the Macintosh Programmer's Workshop, this program can
  14.    be compiled and run as an MPW Tool.  Under other systems,
  15.    it may need some modification.  
  16.  
  17.    This program was written in MPW Pascal v 3.2.
  18.  
  19.                            Jon Bell
  20.               Dept. of Physics & Computer Science
  21.                      Presbyterian College
  22.                        Clinton SC 29325
  23.                     CompuServe: #70441,353
  24.                           October 1991                     }
  25.  
  26.  
  27. Uses RandomNumbers, Events;
  28.  
  29. var
  30. k : longint;
  31. x : extended;
  32. stopTime : longint;
  33.  
  34. begin
  35. InitRandomSeed (1);
  36. writeln;
  37. writeln ('The first ten random numbers are:');
  38. writeln;
  39. for k := 1 to 10 do
  40.     writeln (RandomReal:20:18);
  41. for k := 11 to 10000 do
  42.     x := RandomReal;
  43. writeln;
  44. writeln ('After 10000 iterations,');
  45. writeln ('the random seed is ', RandomSeed:1, '.');
  46. writeln;
  47. k := 0;
  48. stopTime := TickCount + 3600;
  49. while TickCount <= stopTime do
  50.     begin
  51.     x := RandomReal;
  52.     k := k + 1
  53.     end;
  54. writeln ('In one second, ', trunc(k/60):1, 
  55.          ' random numbers were generated.');
  56. writeln
  57. end.
  58.